﻿Module Module1
    Public username_OK As String
    Public txtSQL As String
    Public DBSet As DataSet
    Public ErrorMsg As String

    Public Function ExecuteSQL(ByVal strSQL As String, ByRef errMsg As String) As Integer
        Dim cnn As SqlClient.SqlConnection
        Dim cmd As New SqlClient.SqlCommand()
        Dim adpt As SqlClient.SqlDataAdapter
        Dim rst As New DataSet()
        Dim SplitSQL() As String
        errMsg = ""
        Try
            SplitSQL = Split(strSQL)
            cnn = New SqlClient.SqlConnection(ConnectString())
            If InStr("INSERT,DELECT,UPDATE", UCase$(SplitSQL(0))) Then
                cmd.Connection = cnn
                cmd.Connection.Open()
                cmd.CommandText = strSQL
                ExecuteSQL = cmd.ExecuteNonQuery()
            Else
                adpt = New SqlClient.SqlDataAdapter(strSQL, cnn)
                adpt.Fill(rst)
                ExecuteSQL = rst.Tables(0).Rows.Count
                DBSet = rst
            End If
        Catch ex As Exception
            errMsg = ex.Message
            ExecuteSQL = -1
        Finally
            rst = Nothing
            cnn = Nothing
        End Try
    End Function
    Public Function ConnectString() As String
        ConnectString = "Data Source=DESKTOP-SCAEBMK;Initial Catalog=教学管理;Integrated Security=True"
        'ConnectString = "Data Source=127.0.0.1;Initial Catalog=教学管理;Integrated Security=True"
        'ConnectString = "Data Source=127.0.0.1;Initial Catalog= 教学管理;User ID=sa;Password=end;"
        'ConnectString = "Data Source=127.0.0.1;Initial Catalog=教学管理;User ID=sa;Password=sa;"
    End Function
    Sub main()
        Dim mf As New Register
        mf.ShowDialog()
    End Sub
End Module
